<template>
  <div class="m-login-container">
    <el-row class="m-main-header-search">
      <el-form hide-required-asterisk es="rules" :inline="true" ref="refForm">
        <el-row>
          <el-form-item prop="fs_value" label="模糊搜索">
            <el-input
              clearable
              size="small"
              autofocus
              v-model="refFormData.fs_value"
              placeholder="模糊搜索"
            ></el-input>
          </el-form-item>
          <el-form-item prop="op_type" label="操作类型">
            <el-select
              v-model="refFormData.op_type"
              size="small"
              filterable
              reserve-keyword
              @change="handleSearch"
              placeholder="操作类型"
            >
              <el-option
                v-for="item in vistTypeList"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button @click="handleSearch()" type="primary" size="small">
              查询
            </el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-row>

    <div class="m-main-content-body">
        <p class="contant-body-title">访问明细</p>
      <el-table
        v-loading="loading"
        :data="list"
        tooltip-effect="dark"
        style="width: 100%"
        stripe
        :inline="false"
        :header-cell-style="{
          'background-color': '#E5EEFF',
        }"
      >
        <el-table-column
          prop="id"
          label="ID"
          width="80"
        ></el-table-column>
        <el-table-column
          prop="pre_url"
          label="来源"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="url"
          label="页面地址"
          show-overflow-tooltip
          width="186"

        ></el-table-column>
        <el-table-column
          prop="ip"
          label="ip"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="user_agent"
          label="agent"
          show-overflow-tooltip
          width="186"
        ></el-table-column>
        <el-table-column
          prop="region"
          label="ip区域"
          width="80"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="compose_sn"
          label="套餐组id"
           width="140"
        ></el-table-column>
        <el-table-column
          prop="op_type"
          label="操作类型"
           width="80"
        >
          <template slot-scope="scope">
            {{ scope.row.op_type | visitTypeName }}
          </template>
        </el-table-column>

        <el-table-column
          prop="op_value"
          label="操作值"

        ></el-table-column>
        <el-table-column
          prop="is_paste"
          label="复制"
          width="80"
        >
          <template slot-scope="scope">
            {{ scope.row.op_type | copyTypeName }}
          </template>
        </el-table-column>
        <el-table-column
          prop="time"
          label="时间"
           width="180"
        >
          <template slot-scope="scope">
            {{
              scope.row.time
                ? $moment(scope.row.time).format("YYYY/MM/DD HH:mm:ss")
                : "--"
            }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="(val) => handlePageMetaChange(val, 'size')"
          @current-change="(val) => handlePageMetaChange(val, 'page')"
          :current-page="pageMeta.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageMeta.limit"
          layout="sizes, prev, next, jumper"
          :total="pageMeta.total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import {
  vistTypeList,
  getVisitTypeName,
  getCopyTypeName,
} from "./config/index";

export default {
  components: {},
  filters: {
    visitTypeName: getVisitTypeName,
    copyTypeName: getCopyTypeName,
  },
  data() {
    return {
      list: [],
      loading: false,
      dislogSetVisible: false,
      refFormData: {},
      pageMeta: {
        page: 1,
        limit: 10,
        total: 1e10,
      },
      vistTypeList,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /*
     * @Desc: 获取列表
     * @params: {String}
     * @return: {Object}
     */
    async getList() {
      this.loading = true;
      const { data } = await this.$api.order.getVisitDetailList({
        ...this.pageMeta,
        page: this.pageMeta.page - 1,
        ...this.refFormData,
      });
      const { code, data: list } = data;
      if (code === 200) {
        this.list = list;
      }
      this.loading = false;
    },

    /*
     * @Desc:查询
     * @params: {String}
     * @return: {Object}
     */
    async handleSearch() {
      this.pageMeta.page = 1;
      this.getList();
    },

    /**
     * @Desc 分页
     * @params {String} val page/limit
     * @params {String} type  page/size
     * @return {Object}
     * */
    handlePageMetaChange(val, type = "size") {
      this.pageMeta[type === "size" ? "limit" : "page"] = val;
      this.getList();
    },
  },
};
</script>

<style lang="less" scoped>

/deep/ .table {
  width: calc(100vw - 336px);
}

</style>
